//
//  ChooseProductModel.m
//  DaiShengInvest
//
//  Created by 张睿 on 2017/7/12.
//  Copyright © 2017年 davinci. All rights reserved.
//

#import "ChooseProductModel.h"

@implementation ChooseProductModel

+(instancetype)modelWithDictionary:(NSDictionary *)dic{
    ChooseProductModel *model =[[ChooseProductModel alloc] init];
    
    [model setValuesForKeysWithDictionary:dic];
    
    return model;
}


+(void)headLineListWithSucess:(void (^)(NSArray<ChooseProductModel *> *))sucessBlock error:(void (^)())errorBlock{
    
    
//    [[NetworkTool sharedTools] POST:@"symbols/index" parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *  _Nullable responseObject) {
//        
//        //json
//        //        取第一个key
//        //现在responseObject是个字典，里面只有headline_ad这个元素，怕以后修改headline_ad名字，所以直接获取他的string
//        NSString *rootKey = responseObject.keyEnumerator.nextObject;
//        //取出数组
//        NSArray *array = responseObject[rootKey];
//        
//        NSMutableArray *mArray = [NSMutableArray array];
//        
//        [array enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
//            
//            ChooseProductModel *model = [ChooseProductModel modelWithDictionary:obj];
//            [mArray addObject:model];
//            
//        }];
//        
//        if(sucessBlock){
//            sucessBlock(mArray.copy);
//        }
//        
//    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//        if(errorBlock){
//            errorBlock();
//        }
//    }];
    
    [[NetworkTool sharedTools] POST:@"symbols/index" parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *  _Nullable responseObject) {
        //json
        //        取第一个key
        //现在responseObject是个字典，里面只有headline_ad这个元素，怕以后修改headline_ad名字，所以直接获取他的string
        NSString *rootKey = responseObject.keyEnumerator.nextObject;
        //取出数组
        NSArray *array = responseObject[rootKey];
        
        NSMutableArray *mArray = [NSMutableArray array];
        
        [array enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            
            ChooseProductModel *model = [ChooseProductModel modelWithDictionary:obj];
            [mArray addObject:model];
            
        }];
        
        if(sucessBlock){
            sucessBlock(mArray.copy);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if(errorBlock){
            errorBlock();
        }
    }];
    
}

-(void)setValue:(id)value forUndefinedKey:(NSString *)key{}

@end
